package com.freeseed.model.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.freeseed.model.entity.Classroom;
import com.freeseed.model.mapper.ClassroomMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Allwayz
 * @since 2020-03-20
 */
@Slf4j
@RestController
@RequestMapping("classrooms")
public class ClassroomController {
    @Autowired
    private ClassroomMapper classroomMapper;

    @GetMapping
    public List<Classroom> getClassroomList(){
        List<Classroom> classroomList = classroomMapper.selectList(new QueryWrapper<>());
        return classroomList;
    }

    @GetMapping("{Id}")
    public Classroom getClassroomById(@PathVariable int Id){
        Classroom classroom = classroomMapper.selectById(Id);
        return classroom;
    }

    @PostMapping
    public Classroom addClassroom(Classroom classroom){
        classroomMapper.insert(classroom);
        return classroom;
    }

    @PutMapping
    public Classroom updateClassroom(Classroom classroom){
        classroomMapper.update(classroom,new UpdateWrapper<Classroom>().eq("classroom_id",classroom.getClassroomId()));
        return classroom;
    }

    @DeleteMapping("{Id}")
    public void deleteClassroom(@PathVariable int Id){
        classroomMapper.deleteById(Id);
    }
}
